import com.arangodb.tinkerpop.gremlin.utils.ArangoDBConfigurationBuilder;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;

/**
 * Created By acproject@qq.com on 3/11/22 2:20 PM
 */
public class Test2 {
    public static void main(String[] args) throws Exception {
        ArangoDBConfigurationBuilder builder = new ArangoDBConfigurationBuilder();
        builder.graph("modern")
                .withVertexCollection("software")
                .withEdgeCollection("hardware")
                .withVertexCollection("person")
                .withEdgeCollection("knows")
                .withEdgeCollection("created")
                .configureEdge("knows", "person", "person")
                .configureEdge("created", "person", "software")
                .arangoHosts("172.17.0.3:8529")
                .arangoPassword("root")
                .arangoTimeout(3000)
                .arangoUser("root")
                .dataBase("test2");



// create a ArangoDB graph
        BaseConfiguration conf = builder.build();
        Graph graph = GraphFactory.open(conf);
        GraphTraversalSource gts = new GraphTraversalSource(graph);

// Clone to avoid setup time
        GraphTraversalSource g = gts.clone();
//// Add vertices
//        Vertex v1 = g.addV("person").property(T.id, "1").property("name", "marko")
//                .property("age", 29).next();
//        g = gts.clone();
//        Vertex v2 = g.addV("software").property(T.id, "3").property("name", "lop")
//                .property("lang", "java").next();
//
//// Add edges
//        g = gts.clone();
//        Edge e1 = g.addE("created").from(v1).to(v2).property(T.id, "9")
//                .property("weight", 0.4).next();
//
//// Graph traversal
//// Find "marko" in the graph
//        g = gts.clone();
//        Vertex rv = g.V().has("name","marko").next();
//        assert v1 == rv;
//
//// Walk along the "created" edges to "software" vertices
//        g = gts.clone();
//        Edge re = g.V().has("name","marko").outE("created").next();
//        assert re == e1;
//
//        g = gts.clone();
//        rv = g.V().has("name","marko").outE("created").inV().next();
//// If the edge is irrelevant
//// rv = g.V().has("name","marko").out("created").next();
//        assert rv == v2;
//
//
//// Select the "name" property of the "software" vertices
//        g = gts.clone();
//        String name = (String) g.V().has("name","marko").out("created").values("name").next();
//        assert name.equals("lop");
        System.out.println(gts.V().has("name", "marko").out().as("f").select("f").values().toList());
// close the graph and the traversal source
        gts.close();
        graph.close();
    }
}
